package com.stu.reflection.unsafe_singleton;

import java.lang.reflect.Field;
import sun.misc.Unsafe;

//Unsafe的工具类
public class UnsafeUtil{
	//获取Unsafe实例化对象
	public static Unsafe getUnsafe() {
		try {
			Field field = Unsafe.class.getDeclaredField("theUnsafe");
			field.setAccessible(true);//解除封装处理
			return (Unsafe)field.get(null);//static属性不需要传递实例化对象
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
